﻿// 通过模板 Enumerable_ByMaxMin.tt 自动生成的代码，请勿手工修改！

using System;
using System.Collections.Generic;
using System.Linq;

namespace Viyi.Util.Linq
{
    public static partial class EnumerableExtentions
    {

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, int> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, int> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, short> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, short> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, long> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, long> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, decimal> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, decimal> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, float> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, float> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }

        public static T ByMax<T>(this IEnumerable<T> source,
            Func<T, double> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) > selector(last) ? next: last;
            });
        }

        public static T ByMin<T>(this IEnumerable<T> source,
            Func<T, double> selector)
        {
            return source.Aggregate((last, next) =>
            {
                return selector(next) < selector(last) ? next: last;
            });
        }


    }
}